import React, { useRef, useState, useEffect } from 'react';
import { connect } from 'umi';
import { Alert, Button, Space, Tag, Modal, notification, Row, Col, Checkbox } from 'antd'
import TableDataBlock from '@/components/TableDataBlock';
import SearchCondition from '@/components/SearchCondition';
import { uploadFile } from '@/utils/utils';
const ShareRecord = (props) => {
    const { loading, dispatch, list } = props;
    const childRef = useRef();
    const [params, setSearchParams] = useState({})
    const searchItems = [
        {
            label: '分享人',
            name: 'keyword',
        },
        {
            label: '分享人类型',
            name: 'shareType',
            type: 'select',
            select: {
                admin: "员工",
                user: '用户',
                promoter: '推广员'

            }
        },
        {
            label: '分享手机',
            name: 'shareMobile',
        },
        {
            label: '时间',
            type: 'rangePicker',
            name: 'startTime',
            end: 'endTime',
        },
    ];
    useEffect(() => { childRef.current.initData(); }, [params])
    const fakeExportPromoter = () => {
        dispatch({
            type: 'promoter/fakeExportShareRecord',
            payload: {
                ...params,
            },
            callback: (e) => {
                const { url } = e
                uploadFile(url)
            }
        })

    }
    const getColumns = [
        {
            title: '分享人姓名',
            dataIndex: 'shareName',
        },
        {
            title: '分享手机',
            dataIndex: 'shareMobile',
        },
        {
            title: '分享人类型',

            dataIndex: 'shareType',
            render: (e) => {
                return {
                    admin: "员工",
                    user: '用户',
                    promoter: '推广员'

                }[e];
            },
        },
        {
            title: '分享内容板块',
            dataIndex: 'mediumType',
            render: (e) => {
                return {
                    material: '素材',
                    collect: '信息采集',
                    goods: '商品',
                    thirdGoods: '自主商品 ',
                    thirdPoster: '自主海报 ',
                    thirdMaterial: '自主素材 ',
                }[e]
            }
        },

        {
            title: '内容名称',
            dataIndex: 'mediumName',
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
        },
    ];

    return (
        <Row gutter={[36, 12]}>
            <Col span={24}>
                <TableDataBlock
                    cardProps={{ title: '分享记录' }}
                    content={
                        <Row gutter={[36, 12]}>
                            <Col span={24}>
                                <Space size={'large'}>
                                    <Button type='primary' onClick={() => {
                                        fakeExportPromoter();
                                    }}>导出</Button>
                                </Space>
                            </Col>
                            <Col span={24}>
                                <div style={{ background: '#f5f5f5', padding: 24 }}>
                                    <SearchCondition
                                        handleSearch={(e) => {
                                            setSearchParams(e);
                                        }}
                                        searchItems={searchItems}
                                    ></SearchCondition>
                                </div>
                            </Col>
                        </Row>
                    }
                    cRef={childRef}
                    loading={loading}
                    columns={getColumns}
                    params={{
                        ...params,
                    }}
                    rowKey={(record) => `${record.id}`}
                    dispatchType="promoter/fetchListShareRecord"
                    {...list}
                ></TableDataBlock >
            </Col >
        </Row >
    );
};

export default connect(({ promoter, loading }) => ({
    list: promoter.shareRecordList,
    loading: loading.models.promoter,
}))(ShareRecord);
